/**
 * 聊天会话相关API
 */
import request from '@/utils/request';

/**
 * 获取会话列表（分页）
 * @param {Object} params - 查询参数
 * @param {number} params.current - 当前页码
 * @param {number} params.pageSize - 每页大小
 * @param {string} [params.keyword] - 搜索关键词
 * @param {string} [params.status] - 会话状态
 * @param {string} [params.startDate] - 开始日期
 * @param {string} [params.endDate] - 结束日期
 */
export function getSessionList(params) {
    return request.get('/api/chat/sessions', { params });
}

/**
 * 获取会话详情
 * @param {string} sessionId - 会话ID
 */
export function getSessionDetail(sessionId) {
    return request.get(`/api/chat/session/${sessionId}`);
}

/**
 * 获取活跃会话列表
 */
export function getActiveSessions() {
    return request.get('/api/chat/sessions/active');
}

/**
 * 获取待分配的会话列表
 */
export function getPendingSessions() {
    return request.get('/api/chat/sessions/pending');
}

/**
 * 结束会话
 * @param {string} sessionId - 会话ID
 * @param {string} endReason - 结束原因
 */
export function endSession(sessionId, endReason) {
    return request.post(`/api/chat/session/${sessionId}/end`, { endReason });
}

/**
 * 评价会话
 * @param {string} sessionId - 会话ID
 * @param {number} score - 评分(1-5)
 * @param {string} [evaluation] - 评价内容
 */
export function evaluateSession(sessionId, score, evaluation) {
    return request.post(`/api/chat/session/${sessionId}/evaluate`, {
        score,
        evaluation
    });
}

/**
 * 接受会话分配
 * @param {string} sessionId - 会话ID
 */
export function acceptSessionAssignment(sessionId) {
    return request.post(`/api/chat/session/${sessionId}/accept-assignment`);
}

/**
 * 拒绝会话分配
 * @param {string} sessionId - 会话ID
 * @param {string} reason - 拒绝原因
 */
export function rejectSessionAssignment(sessionId, reason) {
    return request.post(`/api/chat/session/${sessionId}/reject-assignment`, { reason });
}

/**
 * 手动分配会话
 * @param {string} sessionId - 会话ID
 * @param {number} serviceId - 客服ID
 */
export function assignSession(sessionId, serviceId) {
    return request.post(`/api/chat/session/${sessionId}/assign`, { serviceId });
}

/**
 * 获取会话消息列表
 * @param {string} sessionId - 会话ID
 * @param {Object} params - 查询参数
 * @param {number} [params.current] - 当前页码
 * @param {number} [params.pageSize] - 每页大小
 */
export function getSessionMessages(sessionId, params) {
    return request.get(`/api/chat/session/${sessionId}/messages`, { params });
}

export default {
    getSessionList,
    getSessionDetail,
    getActiveSessions,
    getPendingSessions,
    endSession,
    evaluateSession,
    acceptSessionAssignment,
    rejectSessionAssignment,
    assignSession,
    getSessionMessages
}; 